package com.bruce.springai.controller;

import com.bruce.springai.service.ChatService;
import com.bruce.springai.service.VectorStoreService;
import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.List;

@RestController
@RequestMapping("/chat")
public class ChatController {

    @Resource
    private ChatService chatService ;
    @Resource
    private VectorStoreService vectorStoreService ;

    @GetMapping("/chat")
    public Flux<String> chat(@RequestParam String userId, @RequestParam String message) {
        return chatService.chat(userId, message) ;
    }


    @GetMapping("/saveData")
    public boolean saveData(@RequestParam String userId, @RequestParam String message) {
        return vectorStoreService.saveVector(userId, message) ;
    }

    @GetMapping("/history")
    public List<Document> history(@RequestParam String userId,@RequestParam String message) {
        return vectorStoreService.getHistory(userId, message)  ;
    }

    @GetMapping("/load")
    public boolean load() {
       return vectorStoreService.loadData();
    }

    @GetMapping("/ask")
    public List<Document> ask(@RequestParam("q") String question) {
        return vectorStoreService.ask(question);
    }
}
